<?php
/**
 * Created by PhpStorm.
 * User: xiongrui
 * Date: 2017-06-30
 * Time: 17:17
 */

namespace app\admin\validate;



use app\common\exception\Skip;
use think\Request;
use think\Validate;

class BaseValidate extends Validate
{
    public function goVerify(){
        $request = Request::instance();
        $param = $request->param();
        if(!$this->check($param)){
            throw new Skip($this->getError());
        }
        return true;
    }
    /**
     * 验证码校验
     * @param $value [验证值]
     * @param string $rule [验证规则]
     * @param string $data [验证数据]
     * @param string $field [验证字段]
     * @return bool|string
     */
    protected function checkVerify($value, $rule='', $data='', $field=''){
        if(!captcha_check($value)){
            return $field.'验证码不正确';
        }else{
            return true;
        }
    }

    protected function isPositiveInteger($value, $rule='', $data='', $field='')
    {

        if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0) {
            return true;
        }
        return $field . '必须是正整数';
    }

    public function isMobile($value)
    {
        $rule = '^1(3|4|5|7|8)[0-9]\d{8}$^';
        $result = preg_match($rule, $value);
        if ($result) {
            return true;
        } else {
            return false;
        }
    }

}
